﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Dapper;
using System.Data.SqlClient;
using MLSMooc.BO;
using MLSMooc.Helper;
using MLSMooc.DAO.Interface.Feedback;

namespace MLSMooc.DAO.Implement.Feedback
{
    public class FeedbackDAO : IFeedbackDAO
    {
        private static FeedbackDAO instance = new FeedbackDAO();

        private FeedbackDAO() { }
        public static FeedbackDAO Getinstance() => instance;

        private static readonly string queryField = "select mpf.Id ,mpf.Fee_Content ,mpf.Grade,a.LinkName,mpf.CreateTime,mpf.AdminId from Mooc_Project_Feedback mpf join Admin a on mpf.AdminId=a.Id where mpf.isDelete=0";

        public async Task<IEnumerable<FeedbackBO>> GetByIdFeeInfo(int id)
        {
            using (SqlConnection conn=new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(queryField);
                sql.Append($@" and mpf.ProId=@id order by mpf.CreateTime desc");
                var res = await conn.QueryAsync<FeedbackBO>(sql.ToString(), new { id = id });
                return res;
            }
        }
        public async Task<IEnumerable<FeedbackBO>> GetByIdAndAdminIdexist(int ProId, int AdminId)
        {
            using (SqlConnection conn = new SqlConnection(SalesSysSqlHelper.connectionString))
            {
                StringBuilder sql = new StringBuilder(" select * from Mooc_Project_Feedback where ProId=@ProId and AdminId=@AdminId and isDelete=0");
                var res = await conn.QueryAsync<FeedbackBO>(sql.ToString(), new { ProId = ProId, AdminId = AdminId });
                return res;
            }
        }
    }
}
